Skip to content

User selection of HDMI RGB/YCbCr444/YCbCr422 mode - #5249

Merged
pelwell merged 2 commits into
raspberrypi:rpi-5.15.yfrom
6by9:rpi-5.15.y-hdmi
Jan 12, 2023
Merged

pelwell merged 2 commits into
raspberrypi:rpi-5.15.yfrom
6by9:rpi-5.15.y-hdmi

Conversation

@6by9

@6by9 6by9 commented Nov 14, 2022

Copy link
Copy Markdown
Contributor

Replicates the old hdmi_pixel_encoding config.txt option.

@6by9

6by9 commented Nov 14, 2022

Copy link
Copy Markdown
Contributor Author

@mripard You may want to look at the first of these two patches - the swap in vc5_hdmi_set_csc_coeffs_swap is wrong. (I haven't checked that it is the same as mainline, but assume it is).

Comment thread drivers/gpu/drm/vc4/vc4_hdmi.c Resolved
@6by9
6by9 force-pushed the rpi-5.15.y-hdmi branch from aef6f5b to f22f878 Compare January 3, 2023 19:10
@6by9

6by9 commented Jan 3, 2023

Copy link
Copy Markdown
Contributor Author

Patch updated to have a (default) auto mode that behaves as before, and overrides for the other modes.

It also drops the requirement for 4:2:2 to be driven in 12bpc mode. The HDMI spec appears to allow 24, 30, and 36 bpc modes for 4:2:2, even though the packing on the wire is always 36bit. It certainly works (presumably stuffing the data into the MSBs), but I wonder if others agree with handling this.

@nicolasb565

Copy link
Copy Markdown

Is there a way to set that at runtime from userspace in a way that could avoid color format conversion in a gstreamer pipeline?

The use case I have in mind would be to send input from uvc camera YUYV/YUY2 and send that to hdmi 0 output in 4:2:2

Thanks!

@6by9

6by9 commented Jan 4, 2023

Copy link
Copy Markdown
Contributor Author

Is there a way to set that at runtime from userspace in a way that could avoid color format conversion in a gstreamer pipeline?

The use case I have in mind would be to send input from uvc camera YUYV/YUY2 and send that to hdmi 0 output in 4:2:2

This is changing the output format of the HDMI block.
All composition is done in a fully sampled RGB space (ie 420 and 422 have the chroma upsampled and YUV converted to RGB), and the HVS doesn't support YUYV pixel interleaved formats on the input side, so this is of limited use in your use case.

@mripard

mripard commented Jan 6, 2023

Copy link
Copy Markdown
Contributor

I can't really comment for the last one, I don't know the spec well enough. @HiassofT maybe?

The two first patches look fine to me though, so I'm fine with merging this if there's no further comment on the third

@6by9

6by9 commented Jan 6, 2023

Copy link
Copy Markdown
Contributor Author

@mripard - thanks for the response.

As per the commit text, the HDMI 2.0 spec refers to 24, 30, or 36 bit support in 4:2:2, even though on the wire 4:2:2 is always packed as 36 bits.
Having discussed with @popcornmix we're not aware of anything telling the display how many of those 36 bits are being used, so it will presumably use all 12bits, but the HDMI block correctly packs the data in the MSBs anyway, so fundamentally it works.

@nicolasb565

Copy link
Copy Markdown

Would there be a way to just do some kind of "pass through" without having any composition? Basically just send the data over hdmi. My use case does not need composition.

@6by9

6by9 commented Jan 6, 2023

Copy link
Copy Markdown
Contributor Author

Would there be a way to just do some kind of "pass through" without having any composition? Basically just send the data over hdmi. My use case does not need composition.

Please don't hikack a pull request (or unrelated issue) with random requests.

@HiassofT

HiassofT commented Jan 7, 2023

Copy link
Copy Markdown
Contributor

IMO we should leave the YCC 4:2:2 12-bit check in place.

The max_bpc connector property controls output on the wire, which will always be 12 bits for Y and 12 bits for both C comonents in case of YCC 4:2:2 and we added the check to have an easy method of disabling 4:2:2 in auto mode - eg you wouldn't ever want your desktop to run in 4:2:2 or you may also want to disable YCC 4:2:2 because a TV/monitor can't really cope with it.

So we chose to make 4:2:2 opt-in by requring to set max_bpc to 12

Transmitting 8 or 10bit content in 12bit 4:2:2 and padding LSBs is a different thing

@6by9

6by9 commented Jan 7, 2023

Copy link
Copy Markdown
Contributor Author

Auto mode will still try RGB first, so there is no way that you'll get 4:2:2 by accident, and that behaviour hasn't changed.

This new DRM property is intended as an override for the odd cases where displays or capture devices only accept YCbCr 444 or 422, same as we originally had hdmi_pixel_encoding on the legacy stack.

There are several places in HDMI2.0 such as:
Section 5 Overview

HDMI 1.4b also defines a mechanism for transporting YCBCR 4:2:2 Pixels with Pixel sizes of 24, 30, or 36 bits.

Table 7-6 for BT 2020

Bits/component 10 or 12. Pixel encoding RGB or YCBCR 4:2:2 or YCBCR 4:4:4

So it is in the spec that bit depths other than 12 are valid in YCbCr 422, although it's fairly scant on details of how it is intended to be implemented.

It was the annoyance that in order to force 422 you potentially have to also force max_bpc to 12 in the same atomic commit, otherwise the commit fails. You can't necessarily set max_bpc to 12 first in a separate commit as it wouldn't be valid for 4k60 RGB.

we added the check to have an easy method of disabling 4:2:2 in auto mode

Things should be technically correct, not an easy way around a problem.

@HiassofT

HiassofT commented Jan 7, 2023

Copy link
Copy Markdown
Contributor

The spec is quite clear how less than 12 bits per component have to be transmitted, LSB zero padding up to 12 bits

The YC B C R 4:2:2 pixel encoding on HDMI closely resembles standard ITU-R BT.601. The
high-order 8 bits of the Y samples are mapped onto the 8 bits of Channel 1 and the low-order 4
bits are mapped onto the low-order 4 bits of Channel 0. If fewer than 12 bits are used, the valid bits
shall be left-justified (i.e. MSb=MSb) with zeroes padding the bits below the LSb.

It's a 12-bit per component mode and unless you want to change the meaning of max_bpc to mean average bits per component (resembling TMDS character rate) instead of real bits per component then allowing the 12bit 4:2:2 mode with max_bpc != 12 is wrong

@HiassofT

HiassofT commented Jan 7, 2023

Copy link
Copy Markdown
Contributor

Ah, and setting max_bpc to 12 is fine and will work with 4kp60, too - it's only max and the max TMDS rate checks take care that 12 or 10 bit 4:4:4 modes will be rejected

@pelwell

pelwell commented Jan 9, 2023

Copy link
Copy Markdown
Contributor

So is this PR good to merge or not?

6by9 added 2 commits January 12, 2023 12:24
The CSC requires the coefficients to be swapped around for
4:4:4 mode, but the swap was incorrectly defined.

Correct the swap.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
Add a custom property "Output format" that allows the overriding
of the default colourspace choice in the way that the old
firmware hdmi_pixel_encoding property did. If the chosen format is not
supported, then it will still drop back to the older behaviour.

This won't be acceptable to upstream, but it adds back the missing
functionality of hdmi_pixel_encoding.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
@6by9

6by9 commented Jan 12, 2023

Copy link
Copy Markdown
Contributor Author

@HiassofT Thanks for the reference - I'd looked at that section several times and totally missed it.

Let me see if I can sensibly drop the non-12bpc YUV422 patch.
If there's no sensible path to selecting the 422 mode from modetest and xrandr, then it's worthless.

It's getting to the mode in 4k60 that is the niggle.
output_format=auto, max_bpc=12 (will switch to 422), and then you can set output_format=422.
If output_format!=auto, then trying to set max_bpc=12 will fail in 4k60, and it's these weird forcing the order of some changes that I never like. Admittedly 422 support is patchy, but no other DRM driver appears to enforce this.

I can't test that path here at home as I have no 4k monitor, so I'll drop it for now. I may come back to it later.

I've also just noted that explicitly setting "Output format" still checks the EDID for whether that mode is reported as supported. That (correctly) stops me forcing 444 or 422 on the DVI monitor that I happen to have hooked up. We may want to revisit that but too.

@6by9

6by9 commented Jan 12, 2023

Copy link
Copy Markdown
Contributor Author

Branch updated to drop that patch.

@pelwell
pelwell merged commit 64039ee into raspberrypi:rpi-5.15.y Jan 12, 2023
popcornmix added a commit to raspberrypi/firmware that referenced this pull request Jan 13, 2023
kernel: User selection of HDMI RGB/YCbCr444/YCbCr422 mode
See: raspberrypi/linux#5249
popcornmix added a commit to raspberrypi/rpi-firmware that referenced this pull request Jan 13, 2023
kernel: User selection of HDMI RGB/YCbCr444/YCbCr422 mode
See: raspberrypi/linux#5249
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants